<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 200px;
            height: 200px;
            background-color: pink;
        }

        .change{
            background-color: purple;
            color: #fff;
            font-size: 25px;
            margin-top: 100px;
        }
        
        .reduction{
            background-color: pink;
            color: #fff;
            font-size: 25px;
            margin-top: 100px;
        }
    </style>
</head>
<body>
    <div>文本</div>
    <script>
        var div = document.querySelector('div');
        var flag = 0;
        div.onclick = function(){
            //element.style 行内样式修改 
            // if(flag ==0){
            //     div.style.backgroundColor = 'pink';
            //     this.style.width = ' 200px'
            //     flag = 1;
            // }else{
            //     div.style.backgroundColor = 'purple';
            //     this.style.width = '300px'
            //     flag = 0;
            // }


            //element.className 类名样式操作 
            //如果想要保留原先的
            if(flag ==0){
               this.className = 'change';
                flag = 1;
            }else{
                this.className ='reduction';
                flag = 0;
            }

        }

        
        
    </script>
</body>
</html>